//
//  HJCategroyNavBar.m
//  Sneakers
//
//  Created by 胡光健 on 2017/10/20.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HJCategroyNavBar.h"
@interface HJCategroyNavBar () {
    UIButton *_currentbtn;
}

@end
@implementation HJCategroyNavBar

-(instancetype)init {
    if (self = [super init]) {
        self = [[NSBundle mainBundle] loadNibNamed:@"CategroyNavBar" owner:nil options:nil].firstObject;
    }
    return self;
}
-(void)awakeFromNib {
    [super awakeFromNib];
    self.layer.shadowOpacity = 0.25;
    self.layer.shadowRadius = 3;
    self.layer.shadowOffset = CGSizeZero;
    self.layer.shadowColor =HJColorRGB(0).CGColor;
    _currentbtn = [self viewWithTag:10];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self animationLineWithBtn:[self viewWithTag:10]];
    });
   
}

- (void)resetUI {
    [self animationLineWithBtn:_currentbtn];
}

- (IBAction)btn:(UIButton *)sender {
//    [self animationLineWithBtn:sender];
    if ([self.delegate respondsToSelector:@selector(categroyNavBarWithAllBtn:)]) {
        [self.delegate categroyNavBarWithAllBtn:sender];
    }
}
// 滑动线条
-(void)animationLineWithBtn:(UIButton *)btn {
    for (int i = 10; i<=11; i ++) {
        UIButton *view = [self viewWithTag:i];
        view.alpha = 0.5;
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            view.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15];
        });
    }
    btn.alpha = 1;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        btn.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:15];
    });
    [UIView animateWithDuration:0.1 animations:^{
        _line.centerX = btn.centerX;
    }];
    _currentbtn = btn;
}
- (IBAction)searchBtn:(UIButton *)sender {
    if ([self.delegate respondsToSelector:@selector(categroyNavBarWithSearchBtn:)]) {
        [self.delegate categroyNavBarWithSearchBtn:sender];
    }
}
@end
